
Page({

  /**
   * 页面的初始数据
   */
  data: {
    array: ['--请选择--',],
    classify_id:[0],
    index: 0,
    array2: ['--请选择--',],
    index2: 0,
    num:[0,],
    whid:0,
  },
  
  bindPickerChange: function(e) {
    
    this.setData({
      index: e.detail.value
    })
    if(this.data.classify_id[this.data.index] != 0){
        this.goods(this.data.classify_id[this.data.index])
    }else{
      this.setData({array2: ['--请选择--',],})
    }
    
    
  },
  goods(e){
    // console.log(e)
      wx.request({
        url: 'http://39.106.9.207:8080/warehouse/GetGoods',
        data: {
          whid:this.data.whid,
          typeid:e
        },
        header: {
          'content-type': 'multipart/form-data' // 默认值
        },
        success :(res)=>{
          console.log(res.data);
          let array2 = ['--请选择--',];
          let num =[0,];
          var i=0;
          while (i<res.data.length) {
            // console.log(res.data[i].name)
            array2.push(res.data[i].name)
            num.push(res.data[i].goodsNum)
            i++;
          }
          this.setData({
            array2:[],
            array2:array2,
            num:[],
            num,
          })
        }
      })
    },
  bindPicker: function(e) {
    this.setData({
      index2: e.detail.value
    })
    // console.log(this.data.index2)
    //传给后端的日志
    if(this.data.index2 !=0){
      let class_name = this.data.array[this.data.index]
      let goods_name = this.data.array2[this.data.index2]
      // console.log(class_name)
      // console.log(goods_name)
      wx.request({
        url: 'http://39.106.9.207:8080/warehouse/SetLog', 
        data: {
          whid: this.data.whid,
          typename:class_name,
          goodsname:goods_name,
        },
        method: 'POST',
        header: {
          'content-type': 'application/x-www-form-urlencoded;charset=utf-8' // 默认值
        },
        success: (res) => {

        }
      })
    }
  },
  fanhui:function(){
    wx.switchTab({
      url: '/pages/index/index',
    })
  },
  onLoad: function (options) {
    let whid = wx.getStorageSync('warehouseId')
    if (whid) {
      this.setData({
        whid,
      })
    }
    wx.request({
      url: 'http://39.106.9.207:8080/warehouse/GetType', //仅为示例，并非真实的接口地址
      data: {
        whid:this.data.whid,
      },
      header: {
        'content-type': 'multipart/form-data' // 默认值
      },
      success :(res)=>{
        console.log(res.data);
        let array = ['--请选择--',];
        let classify_id = [0];
        var i=0;
        while (i<res.data.length) {
          // console.log(res.data[i].name)
          array.push(res.data[i].name)
          classify_id.push(res.data[i].id)
          i++;
        }
        this.setData({
          array:array,
          classify_id
        })
        // console.log(this.data.classify_id)
      }
    })
  },
})